<#include '/admin/sonheader.html' >
<style>
  .layui-form-checkbox{
    float:left;
  }
   .layui-form-pane .layui-form-label{
 	width:155px;
 }
 .layui-form-pane .layui-input-block{
 	margin-left:155px;
 }
</style>
<div  class="main">    
    <!--表单区域  -->
   <form id="addSmtpForm" class="layui-form layui-form-pane" style="padding-top: 10px;">
		<div class="layui-form-item">
    		<label class="layui-form-label">host:</label>
    		<div class="layui-input-inline">
      			<input type="text"  name="host"  maxlength="50"  lay-verify="required" autocomplete="off" class="layui-input"  />
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">port：</label>
    		<div class="layui-input-inline">
      			<input type="text"  name="port"  maxlength="5"  lay-verify="required|number" autocomplete="off" class="layui-input"  />
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">启用ssl：</label>
    		<div class="layui-input-inline">
      			<input type="radio" name="open_ssl" value="0"  title="否">
      			<input type="radio" name="open_ssl" value="1" title="是" checked="checked">
    		</div>
  		</div> 
  	
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">用户名：</label>
    		<div class="layui-input-inline">
      			<input type="text"  name="username"  maxlength="50"  lay-verify="required" autocomplete="off" class="layui-input"  />
    		</div>
  		</div> 	
  		
  		<div class="layui-form-item">
   	 		<label class="layui-form-label">密码框</label>
    	<div class="layui-input-inline">
      			<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
   		</div>
    	</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">每日最大发信数：</label>
    		<div class="layui-input-inline">
      			<input type="text"  name="max_count"  maxlength="10"  lay-verify="required" autocomplete="off" class="validnum layui-input _inline"  />
    		</div>
    		 <div class="layui-form-mid layui-word-aux">封</div>
  		</div>  
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">from：</label>
    		<div class="layui-input-inline">
      			<input type="text"  name="mail_from"  maxlength="50"  lay-verify="required" autocomplete="off" class="layui-input"  />
    		</div>
  		</div>
  		
  		 <div class="layui-form-item">
     		<input type="checkbox" title="测试" id="add_test_send" lay-filter="add_test_send">
     		
     		<div class="layui-input-inline" id="add_send_span" style="display:none;width:290px;">
      			<input type="text"  name="send_to"  maxlength="50"  autocomplete="off" class="layui-input _inline"  style="display:inline-block;width:150px;height:29px;line-height:29px;float:left;margin:5px 10px 0 10px;"/>
      			<a class="layui-layer-btn0" type="submit" lay-submit="" lay-filter="add_send_button" style="display:inline-block;float:left;margin:5px 0 0 0;height:29px;line-height:29px;">点击发送</a>
    		</div  style="display:none;">

  		</div>
  		<div class="layui-form-item">
     		<div class="layui-input-inline" style="width:290px;">
  					<span id="add_error_message" style="color:red"></span>
    		</div  style="display:none;">
  		</div>
  		<div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;z-index:1000;"> 
  			<a class="layui-layer-btn0" type="submit" lay-submit="" lay-filter="saveSmtp">保存</a>
  			<a class="layui-layer-btn1">取消</a>
  		</div>
   </form>
</div>
<script type="text/javascript">
	$(function(){
		$(".validnum").blur(function(){
			var _self=$(this);
			var val=_self.val();
			if(isNaN(parseInt(val))){
				alert("您输入的不是数字");
				_self.val(1);
			}else if(parseInt(val)<1){
				alert("输入的不能小于1");
				_self.val(1);
			}else{
				_self.val(parseInt(val));
			}
		});
	});
	
	var index = parent.layer.getFrameIndex(window.name);

	layui.use(['form', 'layedit', 'laydate'], function(){
	    var form = layui.form()
	        ,layer = layui.layer
	        ,layedit = layui.layedit
	        ,laydate = layui.laydate;
	    
	    $(".layui-layer-btn1").click(function(){
	    	parent.layer.close(index);
	    });
	    
	    layui.use(['form'], function(){
		    var form = layui.form();
		    
		    form.on('checkbox(add_test_send)', function(data){
		    	if(data.elem.checked){		   
		    		$("#add_send_span").show();
		    	}else{
		    		$("#add_send_span").hide();
		    	}
		    });  
		});
	    
	    //监听提交
	    form.on('submit(saveSmtp)', function(data){
	    	var options = {
	   			url:"save-add.do",
	   			type:"post",
	   			dataType:"json",
	   			success:function(data){
	   				if(data.result==1){	
	   					parent.$.Loading.success(data.message);
	   					parent.layer.close(index); //再执行关闭        
	   					parent.table.ajax.url("smtp-listJson.do").load();
	   				}
	   			}
	   		};
	   		$("#addSmtpForm").ajaxSubmit(options);
	       return false;
	    });
	  //监听提交
	    form.on('submit(add_send_button)', function(data){
	    	var testbtn=$(this);
	    	var error=$("#add_error_message");
			if(!testbtn.hasClass("disable")){
					testbtn.addClass("disable");
					$("#add_send_button").hide();
					$(".show-lodding").show();
					var options = {
						url : "test-send.do",
						type : "POST",
						dataType : "json",
						success : function(result) {
							if(result.result==1){
								parent.$.Loading.success("发送测试邮件成功");
								error.html("11");
							}else{
								parent.$.Loading.error("发送测试邮件失败");
								error.html(result.message);
							}
							testbtn.removeClass("disable");
							$("#add_send_button").show();
							$(".show-lodding").hide();
					 	},
					 	error : function(e) {
					 		parent.$.Loading.error('出现错误，请重试');
					 		testbtn.removeClass("disable");
					 		error.html(e.message);
					 		$("#add_send_button").show();
							$(".show-lodding").hide();
						}
					};
					$('#addSmtpForm').ajaxSubmit(options);	
					return false;
			}
	    });
	});
</script>


